import java.util.Arrays;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        int year = 20200202;
        System.out.println(nextBackDay(year));
        System.out.println(nextAbBackDay(year));
    }
    public static int nextAbBackDay(int n){

        int x = nextBackDay(n);
        int copy = x;
        int[] arr = new int[8];
        for (int i = 0; i < 8; i++) {
            arr[i] = x%10;
            x /= 10;
        }
        if(arr[0] == arr[2] && arr[5]==arr[2] && arr[7] == arr[5] && arr[1] == arr[3] &&arr[3] ==arr[4]&&arr[4] ==arr[6]){
            return copy;
        }
        return nextAbBackDay(copy);
    }
    public static int nextBackDay(int n){
        int year = n/10000;
        int month = (n/100)%100;
        int day = n%100;
        if(month == 1||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12){
            if (day < 31){
                day++;
            }
            day = 1;
            if(month < 12){
                month++;
            }else{
                year++;
                month=1;
            }
        }else{
            if(day < 30){
                day++;
            }
            day = 1;
            if(month < 12){
                month++;
            }else{
                year++;
                month=1;
            }
        }
        while (true){
            if(month == 1||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12){
                while (day < 31){
                    if(isBack(year*10000+month*100+day)) {
                        return year*10000+month*100+day;
                    }
                    day++;
                }
                day = 1;
                if(month < 12){
                    month++;
                }else{
                    year++;
                    month=1;
                }
            }else{
                while (day < 30){
                    if(isBack(year*10000+month*100+day)) {
                        return year*10000+month*100+day;
                    }
                    day++;
                }
                day = 1;
                if(month < 12){
                    month++;
                }else{
                    year++;
                    month=1;
                }
            }
        }
    }
    public static boolean isBack(int year) {
        int copy = year;
        int[] arr = new int[8];
        for (int i = 7; i >= 0; i--) {
            arr[i] = copy % 10;
            copy = copy / 10;
        }
        int left = 0;
        int right = 7;
        while (left < right){
            if(arr[left] != arr[right]){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 0; i < arr.length; i++) {
            arr[i] = scanner.nextInt();
            sum1 += arr[i];
            sum2 += arr[i]*arr[i];
        }
        System.out.println((sum1*sum1-sum2)/2);
    }//用数学思维
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long sum = 0;
        long a[] = new long[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = scanner.nextLong();
        }
        int left = 0;
        int right = a.length-1;
        int key = 1;
        while (left < right){
            if(key == 1){
                long copy = a[left];
                for (int i = left+1; i < right+1; i++) {
                    sum += copy * a[i];
                }
                left++;
            }
            if(key == -1){
                long copy = a[right];
                for (int i = right-1; i >= left ; i--) {
                    sum += copy * a[i];
                }
                right--;
            }
            key *= -1;
        }
        System.out.println(sum);
    }//嵌套for循环
}